# Maintainer: Antonio Rojas <arojas@archlinux.org>

pkgname=spglib
pkgver=2.1.0
pkgrel=2
pkgdesc='C library for finding and handling crystal symmetries'
arch=(loong64 x86_64)
url='https://spglib.readthedocs.io/en/latest/'
license=(custom)
depends=(glibc)
makedepends=(cmake
             gcc-fortran
             gtest
             python
             python-numpy)
optdepends=('gcc-libs: Fortran interface'
            'python-numpy: Python interface')
source=(https://github.com/spglib/spglib/archive/v$pkgver/$pkgname-$pkgver.tar.gz
        fix-duplicate-libs.patch)
sha256sums=('31bca273a1bc54e1cff4058eebe7c0a35d5f9b489579e84667d8e005c73dcc13'
            '07e887901ddc521907eaf8d9e1632e5935554f544690c2744f9f66b05d104341')

prepare() {
  patch -d $pkgname-$pkgver -p1 < fix-duplicate-libs.patch # Don't duplicate shared libs in python tree
}

build() {
  cmake -B build -S $pkgname-$pkgver \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DSPGLIB_WITH_Fortran=ON \
    -DSPGLIB_WITH_Python=ON
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -Dm644 "$srcdir"/$pkgname-$pkgver/COPYING "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
